﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlServerCe;
using System.Data;
using System.IO;

public partial class _4devolop_creaTabelle : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        var sconn = @"Data Source=|DataDirectory|\Genesi.sdf";
        string sql = "";
        sql = query.Text;
        //string sfiname = (Server.MapPath("~") + @"/scripts/Genesi.sql");
        //string FileName = Server.MapPath("../scripts/Genesi.sql");
        

        //using (StreamReader objStreamReader = File.OpenText(FileName))
        //{
        //    sql = objStreamReader.ReadToEnd();
        //}
        
        if (!string.IsNullOrEmpty(sql))
        {
            SqlCeConnection cn = new SqlCeConnection(sconn);
            if (cn.State == ConnectionState.Closed)
            {
                cn.Open();

            }
            SqlCeCommand cmd;
            //        string sql = @"create table CoolPeople (
            //        LastName nvarchar (40) not null, 
            //        FirstName nvarchar (40), 
            //        URL nvarchar (256) )";

            cmd = new SqlCeCommand(sql, cn);

            try
            {

                cmd.ExecuteNonQuery();
                lblResults.Text = "Table Created.";
            }
            catch (SqlCeException sqlexception)
            {
                Response.Write(sqlexception.Message);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
    }
}